<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>数据源</title>
    <%@include file="/WEB-INF/jsp/include.jsp"%>

    <style type="text/css">
        .icon-xls {
            background: url("${path }/images/excel.png") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
        }
    </style>
    <script type="text/javascript">

        var path = "${path}";
        var params = {};
        var url = '${path}/system/ds/queryByPage';

        $(function() {
            //设置AjaxLoading
            setAjaxLoading();
            var grid = $("#dstab");
            initGrid(grid);

            $("#dsName").bind('keyup', function(event) {
                if(event.keyCode ==13){
                    btnQuery();
                }
            });
            $("#dbURL").bind('keyup', function(event) {
                if(event.keyCode ==13){
                    btnQuery();
                }
            });

            btnQuery();
        });

        //初始化表格和数据
        function initGrid(grid) {
            var columns = [
                { field: "id", title: "ID", hidden: true, align: "left", sortable: false, resizable: true, width: 120},        
                { field: "dsName", title: "数据源名称", align: "left", halign: "center", sortable: false, resizable: true, width: 130},
                { field: "dbType", title: "数据库类型", align: "left", halign: "center", sortable: false, resizable: true, width: 135},
                { field: "dbURL", title: "数据库地址", align: "left", halign: "center", sortable: false, resizable: true, width: 200},
                { field: "dbPort", title: "端口", align: "left" , halign: "center", sortable: false, resizable: true, width: 150},
                { field: "dbName", title: "服务名/数据库名", align: "left",halign: "center", sortable: false, resizable: true, width: 190},
                { field: "dbUser", title: "账号", align: "left" ,halign: "left", sortable: false, resizable: true, width: 120},
                { field: "minConn", title: "最小连接数", align: "left" ,halign: "left", sortable: false, resizable: true, width: 120},
                { field: "maxConn", title: "最大连接数", align: "left" ,halign: "left", sortable: false, resizable: true, width: 120}
            ];
            //var grid = $("#dstab").datagrid({'columns': columns});
            initPageGrid(grid, params, url, columns, "#bstoolbar");
            btnQuery();
        }

        // 查询按钮
        function btnQuery() {
            params.dsName = $("#dsName").val();
            params.dbName = $("#dbName").val();
            params.dbURL = $("#dbURL").val();
            params.dbType = $("#dbType").combobox("getValue");
            // 重新刷新分页
            params.pageNumber = 1;
            var grid = $("#dstab");
            getPage(grid, params, url);
            $('#dstab').datagrid('reload');
        }

        // 新增数据源
        function btnAddNode() {
            layer.open({
                type: 2,
                title: '数据源管理 - 添加',
                shadeClose: false,
                shade: 0.3,
                area: ['710px', '300px'],
                content: '${path}/system/ds/toAdd'
            });
        }

        // 修改数据源
        function btnEditNodeByGrid(){
            var rows = $('#dstab').datagrid('getSelections');
            if (rows.length == 0) {
                $.alert("pick", "info", "数据");
                return;
            }
            layer.open({
                type: 2,
                title: '数据源管理  - 修改',
                shadeClose: true,
                shade: 0.3,
                area: ['710px', '300px'],
                //content: '${path}/system/ds/toUpdate' //iframe的url
                //content: 'web/system/ds/toUpdate' //iframe的url
                content: '${path}/system/ds/toUpdate'
            });
        }

        // 删除数据源
        function btnDelNodeByGrid() {
            var rows = $('#dstab').datagrid('getSelections');
            if (rows.length == 0) {
                $.alert("pick", "info", "数据");
                return;
            }
            var rowData = rows[0];
            var param = {};
            param.id = rowData.id;
            $.messager.alert("问题", "请确认是否要删除？","confirm", function () {

                    $.ajax({
                        type: "POST",
                        //url: path+'/system/ds/delete',
                        url: '${path}/system/ds/delete',
                        data: param,
                        dataType: "json",
                        async: false,
                        success: function callback(data) {
                            var analyMsg = data;
                            if(analyMsg.code!="0000") {
                                $.alert("delete", "error", "数据");
                            } else {
                                $.alert("delete", "info", "数据");
                            }
                        },
                        error: function(data, textstatus) {
                            $.alert("delete", "error", "数据");
                        }
                    });
            });
        }
    </script>
</head>

<body style="margin:0px; padding:0px;">
    <div class="easyui-layout" fit="true">
        <div region="center" style="padding: 5px;" border="false">
            <div class="easyui-layout" fit="true" border="false">
                <div id="divNorth" region="north" title="查询条件" border="true" noheader="false" style="padding: 5px; height: 71px; background: none repeat scroll 0 0 #EFEFEF;">
                    <table>
                        <tr>
                            <td>数据源名称：</td>
                            <td>
                                <input class="query_input" type="text" id="dsName" name="dsName" style="width: 180px" />
                            </td>
                            <td>服务/数据库/数据源名称：</td>
                            <td>
                                <input class="query_input" type="text" id="dbName" name="dbName" style="width: 180px" />
                            </td>
                            <td>数据库URL</td>
                            <td>
                                <input class="query_input" type="text" id="dbURL" name="dbURL" style="width: 180px" />
                            <td>数据库类型：</td>
                            <td>
                                <select id="dbType" name="dbType" class="easyui-combobox" data-options="panelWidth:160" style="width: 160px;">
                                    <option value="">---请选择---</option>
                                    <option value="Oracle">Oracle</option>
                                    <option value="DB2">DB2</option>
                                    <option value="MySQL">MySQL</option>
                                    <option value="SQLServer">SQLServer</option>
                                    <option value="Sybase">Sybase</option>
                                    <option value="ODBC">ODBC</option>
                                </select>
                            </td>
                            <td><input class="search-btn-blue" style="margin-left:10px" type="button" onclick="btnQuery();" value="查询"></td>
                        </tr>
                    </table>
                </div>
                <div region="center" title="" border="false" noheader="true"
                    style="padding: 5px 0 0 0;">
                    <table id="dstab" title="" border="false"></table>
                </div>
            </div>
        </div>
    </div>

    <iframe id="ifile" style="display:none"></iframe>
    <div id="bstoolbar" style="padding: 1px; height: auto; display: none;">
        <div>
            <a id="btn_addNode_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="false" onclick="btnAddNode()">新增</a>
            <a id="btn_editNode_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="false" onclick="btnEditNodeByGrid()">修改</a>
            <a id="btn_delNode_tb" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="false" onclick="btnDelNodeByGrid()">删除</a>
        </div>
    </div>
</body>
</html>
